<?php 
	
	
	require '../include/library.inc.php';
	
	
	if($_GET["lang"])

	{
		
		
			$sql = "SELECT lang_id,code FROM language WHERE code ='".escape($_GET["lang"])."' ";
		
			$result_lang = query($sql);
		
			$row_lang = mysql_fetch_object($result_lang);
			if($row_lang)
			{
			$_SESSION["lang_id"] = $row_lang->lang_id;
			$_SESSION["lang"] = $row_lang->code;
			
			
			}
			
			
	}else{

		//redirect(HTML_BASE.'bg/');

	}

	if(!$_SESSION["lang"]  ){
	
		$sql = "SELECT lang_id,Name,code FROM language WHERE published  ORDER BY  	order_number LIMIT 1 ";
	
		$result_lang = query($sql);
	
		$row_lang = mysql_fetch_object($result_lang);		
		$_SESSION["lang_id"] = $row_lang->lang_id;		
		$_SESSION["lang"] = $row_lang->code;
		
		}
	
	
		if(!file_exists('../languages/'.$_SESSION["lang"].'.const.php'))
	
		{
	
			$_SESSION["lang_id"] = '1';
	
			$_SESSION["lang"] = 'en';
	
		}

		require '../languages/'.$_SESSION["lang"].'.const.php';



		
			$tmp = 'home';
			if(!$_REQUEST["prm1"]) $tmp = 'home';
			
			if($_GET["prm1"]) $tmp = $_GET["prm1"];
			
			$sef_url = escape($_REQUEST["prm1"]);
			
			if(escape($_REQUEST["prm2"])) $sef_url = escape($_REQUEST["prm2"]);
			
			if($_REQUEST["prm1"] && !file_exists( './tamplates/'.$_REQUEST["prm1"].'.tmp.php' ))
			{
				
				
				$sql = "SELECT page_id 
						FROM pages
						WHERE sef_url = '".escape($_REQUEST["prm1"])."'  AND published";
				$result = query($sql);
				if(mysql_numrows($result) ){
					 $tmp = 'page';
				     $sef_url = escape($_REQUEST["prm1"]);
				}
				
			}
			
			
			if($_REQUEST["prm1"] == 'news' && $_REQUEST["prm2"])
			{
				
				
				$sql = "SELECT new_id 
						FROM news
						WHERE sef_url = '".escape($_REQUEST["prm2"])."'  AND published";
				$result = query($sql);
				if(mysql_numrows($result) ){
					 $tmp = 'newsview';
				     $sef_url = escape($_REQUEST["prm2"]);
				}
				
			}
			
			
			if(!file_exists( './tamplates/'.$tmp.'.tmp.php' )) $tmp = 'home';
			
			if($_REQUEST["prm2"]) $_GET["frompage"] = $_GET["prm2"];
			
			require 'tamplates/'.$tmp.'.tmp.php';;
		

?>


